﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;

namespace WeiSha.Core
{
	// Token: 0x0200000B RID: 11
	public class Log
	{
		// Token: 0x17000013 RID: 19
		// (get) Token: 0x06000044 RID: 68 RVA: 0x0000378C File Offset: 0x0000198C
		public static int LOG_LEVEL
		{
			get
			{
				bool flag = Log.log_level >= 0;
				int num;
				if (flag)
				{
					num = Log.log_level;
				}
				else
				{
					int valueOrDefault = App.Get["LOG_LEVEL"].Int16.GetValueOrDefault();
					Log.log_level = ((valueOrDefault >= 0) ? valueOrDefault : valueOrDefault);
					num = Log.log_level;
				}
				return num;
			}
		}

		// Token: 0x06000045 RID: 69 RVA: 0x000037E4 File Offset: 0x000019E4
		public static void Debug(string className, string content)
		{
			bool flag = Log.LOG_LEVEL >= 3;
			if (flag)
			{
				Log.WriteLog("DEBUG", className, content);
			}
		}

		// Token: 0x06000046 RID: 70 RVA: 0x00003810 File Offset: 0x00001A10
		public static void Info(string className, string content)
		{
			bool flag = Log.LOG_LEVEL >= 2;
			if (flag)
			{
				Log.WriteLog("INFO", className, content);
			}
		}

		// Token: 0x06000047 RID: 71 RVA: 0x0000383C File Offset: 0x00001A3C
		public static void Error(string className, string content)
		{
			bool flag = Log.LOG_LEVEL >= 1;
			if (flag)
			{
				Log.WriteLog("ERROR", className, content);
			}
		}

		// Token: 0x06000048 RID: 72 RVA: 0x00003868 File Offset: 0x00001A68
		public static void Error(string className, Exception ex)
		{
			bool flag = Log.LOG_LEVEL >= 1;
			if (flag)
			{
				string text = "";
				text = text + "Message:" + ex.Message + "\n\r";
				text = text + "Source:" + ex.Source + "\n\r";
				text = text + "StackTrace:" + ex.StackTrace + "\n\r";
				string text2 = text;
				string text3 = "TargetSite:";
				MethodBase targetSite = ex.TargetSite;
				text = text2 + text3 + ((targetSite != null) ? targetSite.ToString() : null) + "\n\r";
				text = text + "ToString:" + ex.ToString() + "\n\r";
				Log.WriteLog("ERROR", className, text);
				bool flag2 = ex.InnerException != null;
				if (flag2)
				{
					Log.Error(className, ex.InnerException);
				}
			}
		}

		// Token: 0x06000049 RID: 73 RVA: 0x00003938 File Offset: 0x00001B38
		protected static void WriteLog(string logtype, string className, string content)
		{
			string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
			string text = string.Concat(new string[]
			{
				Log.log_path,
				"/",
				logtype,
				"/",
				className.Replace(".", "_")
			});
			string filepath = baseDirectory + text;
			string text2 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
			string filename = filepath + "/" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
			List<string> list = new List<string>();
			list.Add(string.Format("{0}: {1}, {2} : ", logtype, text2, className));
			string[] array = content.Split(new char[] { '\n' });
			foreach (string text3 in array)
			{
				list.Add(text3);
			}
			new Task(delegate
			{
				Log._writeLog(filepath, filename, list);
			}).Start();
		}

		// Token: 0x0600004A RID: 74 RVA: 0x00003A5C File Offset: 0x00001C5C
		private static void _writeLog(string filepath, string filename, List<string> context)
		{
			bool flag = !Directory.Exists(filepath);
			if (flag)
			{
				Directory.CreateDirectory(filepath);
			}
			using (StreamWriter streamWriter = File.AppendText(filename))
			{
				for (int i = 0; i < context.Count; i++)
				{
					streamWriter.WriteLine(context[i]);
				}
				streamWriter.WriteLine();
				streamWriter.Close();
			}
		}

		// Token: 0x04000014 RID: 20
		private static string log_path = "logs";

		// Token: 0x04000015 RID: 21
		private static int log_level = -1;
	}
}
